<template>
  <mt-tabbar v-model="message" fixed>
    <mt-tab-item v-for="tab in atabs" :id="tab.id">
      <img slot="icon" :src="tab.icon">
      {{tab.name}}
    </mt-tab-item>
  </mt-tabbar>
</template>

<script>
  export default {
    data(){
      return{
        //选中的tabbar值message为外面页面传入的值selected
        message:this.selected,
        //这里使用的icon图标为图片，所以需要加图片改变的传入，若使用阿里图标，则不用加
        atabs:this.tabs,
      }
    },
    props:{
      selected: String,
      tabs:Array,
    },
    watch: {
      message: function (val, oldVal) {
        // 这里就可以通过 val 的值变更来确定去向
        console.log(val);
        this.$router.push({path:"/"+val});
        this.$parent.selected = val;
        window.sessionStorage.setItem('navTabIndex',val);
/*      case 'ShoppingList':
        this.$router.push('/shoppinglist');*/
      },
      selected:function (val, oldVal) {
        if(val){
          this.message = val;
        }
      }
    },created: function(){
        let localData = window.sessionStorage.getItem('navTabIndex');
        if(localData){
          this.message = localData;
        }
    }
  }
</script>
